package cate.game.role.res.call;

import cate.common.table.call.row.CallWeightRow;
import cate.common.table.d.GDHeroCall;
import cate.common.table.item.hero.StarGroupList;
import cate.common.util.GameResult;
import cate.game.role.Role;
import cate.game.role.res.call.base.*;
import easy.java.dev.note.NoteClass;


@NoteClass(value = "召唤表中通用配置处理流程")
public class CallCommonBaseHandler<T extends CallBasePO> implements ICallHandler {
  /**
   * 所有抽取之前的检测
   *
   * @param
   * @param role
   * @param processData
   * @param basePO
   * @return
   */
  @Override
  public boolean callPreCheck(Role role, CallProcessData processData, CallBasePO basePO) {
    if (!basePO.tool.checkVip(role, processData.base)) {
      return false;
    }
    if(basePO.getMode()!= GDHeroCall.Mode.NATURE){
      if (!basePO.tool.checkBag(role, role.getBag().hero, processData.base)) {
        return false;
      }
    }
    //免费刷新间隔检查,需要记录在不同模块数据自行检查
    if (basePO.tool.checkFree(processData, basePO)) {
      basePO.tool.costFreeReset(basePO);
      return true;
    }

    // 积分检测
    if (basePO.tool.checkScore(role, processData)) {
      basePO.tool.costScore(role, processData);
      return true;
    }

    // 友情点检测
    if (basePO.tool.checkFriendPoint(role, processData)) {
      return true;
    }

    //召唤券检测
    if (basePO.tool.checkProp(role, processData)) {
      return true;
    }

    //钻石检测
    if (basePO.tool.checkCostM1(role, processData)) {
      basePO.tool.costM1(role, processData);
      return true;
    }

    role.getGame().notice.message(role, 310203, "道具不足");
    return false;
  }


  @Override
  public void singleCallExe(Role role, CallProcessData processData, CallBasePO basePO) {
    processData.base.config.setup();
    StarGroupList.Item group = processData.base.config.get();
    if (group == null) {
      role.getGame().notice.message(role, "配置错误");
      return;
    }
    CallResult item = null;
    //普通模式
    CallWeightRow row = basePO.tool.doGeneralCall(role, group.groupId);
    if (row == null) {
      return;
    }
    item = new CallResult(processData.consumedTimes + 1, row.id);

    processData.result.add(item);
  }

  @Override
  public void singleCallAffect(Role role, CallProcessData processData, CallBasePO basePO) {
  }

  @Override
  public void modifyByDifferentMod(Role role, CallProcessData processData, CallBasePO basePO) {
    basePO.tool.forceAppointPoolReCall(role, processData, basePO);
    basePO.tool.limitStarFiveHeroNum(role, processData, basePO);
  }


  @Override
  public GameResult calcResult(Role role, CallProcessData processData, CallBasePO basePO) {
    GameResult r = processData.consumeCost(role);
    if (!r.ok()) {
      role.getGame().notice.message(role, 310203, "道具不足");
      return r;
    }
    basePO.tool.resultAddNotice(role, processData);
    return r.success();
  }
}
